/*************************************************************************
	> File Name: hzoj_245.cpp
	> Author: zhangxu
	> Mail: 
	> Created Time: 二  8/20 11:57:37 2024
 ************************************************************************/

#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 100000

int arr[MAX_N + 5];

int main() {
	int n;
	cin >> n;
	for(int i = 0;i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int p = arr[n / 2], ans = 0;
	for(int i = 0; i < n; i++) {
		ans += abs(p - arr[i]);
	}
	cout << ans << endl;
	return 0;
}
